package com.ibeeking.found.common.config.feign.fallback;

import com.ibeeking.found.common.config.feign.TenantUserClient;
import com.ibeeking.found.common.entity.LoginOpenUserDTO;
import com.ibeeking.found.common.entity.UserInfoDTO;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class TenantUserFallbackFactory implements FallbackFactory<TenantUserClient> {
    @Override
    public TenantUserClient create(Throwable throwable) {
        return new TenantUserClient() {
            @Override
            public ResponseResult<UserInfoDTO> queryLoginUser(Long userId) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，根据用户Id查询用户信息失败。" + throwable.getMessage());
            }

            @Override
            public ResponseResult<LoginOpenUserDTO> queryLoginUser(String appId) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，根据用户Id查询用户信息失败。" + throwable.getMessage());
            }

            @Override
            public ResponseResult<List<String>> queryApis(Long currentId, String traceId, String tenantId, String userId, String name, String loginRole, String loginSystem) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，根据用户Id查询用户信息失败。" + throwable.getMessage(), Collections.emptyList());
            }
        };
    }
}
